function Fig=PlotNiceMatrix(Matrix,Fig)
%%
[YVarNum,XVarNum]=size(Matrix);
%% Check Figure handel
if nargin<2
    a=figure();
    Fig.Fig=a;
end
if isnumeric(Fig)
    Temp=Fig;
    clear Fig
    Fig.Fig=Temp;
end
%% Text, Title and Labels
if ~isfield(Fig,'TextSize')
    Fig.TextSize=14;
end
if ~isfield(Fig,'TextStyle')
    Fig.TextStyle='%3.2e';
end
if ~isfield(Fig,'Title')
    Fig.Title='';
end
if ~isfield(Fig,'YLabel')
    Fig.YLabel='';
end
if ~isfield(Fig,'XLabel')
    Fig.XLabel='';
end
if ~isfield(Fig,'XVarName')
    Fig.XVarName=1:XVarNum;
end
if ~isfield(Fig,'YVarName')
    Fig.YVarName=1:YVarNum;
end
if ~isfield(Fig,'YVarNameAngel')
    Fig.YVarNameAngel=0;
end

%% Pos
if ~isfield(Fig,'TypeValues')
    Fig.TypeValues=true;
end
if Fig.TypeValues
    if ~isfield(Fig,'TypeValuesPos')
        [Fig.TypeValuesPos{1},Fig.TypeValuesPos{2}]=meshgrid(0.5:1:XVarNum,0.5:1:YVarNum);
    end
end

%% Color Map and Colorbar
if ~isfield(Fig,'ColorMAP')
    Fig.ColorMAP='autumn';
end
if ~isfield(Fig,'ColorRenge')
    Fig.ColorRenge=[0,max(max(Matrix))];
end
if ~isfield(Fig,'ColorBar')
    Fig.ColorBar=true;
end
%% Scatter Size
if ~isfield(Fig,'ScatterSize')
    Fig.ScatterSize=2;
end
%% Correct Axis
if isfield(Fig,'Fig')
    figure(Fig.Fig)
else
    figure()
end

if isfield(Fig,'SubFig')
    if length(Fig.SubFig)==3
        subplot(Fig.SubFig{1},Fig.SubFig{2},Fig.SubFig{3})
    else
        subplot(Fig.SubFig)
    end
end

%% Plot Back
Extended=Matrix;
Extended(end+1,:)=Extended(end,:);
Extended(:,end+1)=Extended(:,end);
[X,Y]=meshgrid(0:XVarNum,0:YVarNum);
cla
surf(X,Y,Extended,'facealpha',0.5,'edgecolor','k')

view(2);
colormap(Fig.ColorMAP);
caxis(Fig.ColorRenge)
if Fig.TypeValues
    for i=1:YVarNum
        for j=1:XVarNum
            text(Fig.TypeValuesPos{1}(i,j),Fig.TypeValuesPos{2}(i,j),max(max(Matrix)),num2str(Matrix(i,j),Fig.TextStyle),'FontSize',Fig.TextSize-2,'HorizontalAlignment','center')
        end
    end
end
if ~isempty(Fig.Title)
    title(Fig.Title,'interpreter','tex')
end
if ~isempty(Fig.YLabel)
    ylabel(Fig.YLabel)
end
if ~isempty(Fig.XLabel)
    xlabel(Fig.XLabel)
end
if Fig.ColorBar
colorbar('Location','eastoutside');
end
ylim([0,YVarNum]);
xlim([0,XVarNum]);
set(gca,'XAxisLocation','top')
set(gca,'YDIR','reverse')
set(gca,'TickLength',[0,0])
xticks(0.5:XVarNum);
yticks(0.5:YVarNum);
xticklabels(Fig.XVarName);
yticklabels(Fig.YVarName);
ytickangle(Fig.YVarNameAngel);

%% 
grid off
set(gca,'FontSize',Fig.TextSize)
if isfield(Fig,'Position')
    set(Fig.Fig,'position',Fig.Position);
end